package edu.whu.demo.dao;

import edu.whu.demo.domain.Supplier;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jzw
 * @since 2022-10-28
 */
@Mapper
public interface SupplierDao extends BaseMapper<Supplier> {

    /**
     * 根据产品id查询对应的supplier
     * @param productId 产品id
     * @return List<Supplier>
     */
    @Select("SELECT supplier.* FROM supplier, product_supplier WHERE product_supplier.product_id=#{productId} and product_supplier.supplier_id=supplier.id")
    List<Supplier> findSuppliersByProductId(long productId);

    @Select("INSERT INTO product_supplier (product_id, supplier_id) VALUES (#{productId},#{supplierId})")
    void setProductSupplier(long productId, long supplierId);
}
